package com.mywang.weitravel.modules.register;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.mywang.weitravel.R;
import com.mywang.weitravel.base.BaseActivity;
import com.mywang.weitravel.util.ScreenUtil;

import butterknife.BindView;
import butterknife.OnClick;
import me.jessyan.autosize.internal.CustomAdapt;

public class RegisterActivity extends BaseActivity<RegisterPresenter> implements RegisterContract.View, CustomAdapt {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.et_user_name)
    EditText etUserName;
    @BindView(R.id.et_password)
    EditText etPassword;
    @BindView(R.id.et_confirm_password)
    EditText etComfirmPassword;
    @BindView(R.id.btn_register)
    Button btnRegister;

    @Override
    protected int getActivityLayoutID() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected RegisterPresenter initPresenter() {
        return new RegisterPresenter(this);
    }

    @OnClick({R.id.tv_title, R.id.btn_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_title:
                finish();
                break;
            case R.id.btn_register:
                doRegister();
                break;
        }
    }

    private void doRegister() {
        String userName = etUserName.getText().toString();
        String password = etPassword.getText().toString();
        String confirm_password = etComfirmPassword.getText().toString();

        if (userName.isEmpty()) {
            ToastUtils.showShort("请输入用户名");
            return;
        }
        if (userName.length() < 6) {
            ToastUtils.showShort("请输入6-20位用户名");
            return;
        }
        if (password.isEmpty()) {
            ToastUtils.showShort("请输入密码");
            return;
        }
        if (userName.length() < 6) {
            ToastUtils.showShort("请输入6-12位密码");
            return;
        }
        if (confirm_password.isEmpty()) {
            ToastUtils.showShort("请输入确认密码");
            return;
        }
        if (confirm_password.length() < 6) {
            ToastUtils.showShort("请输入6-12位确认密码");
            return;
        }

        mPresenter.doRegister(userName, password, confirm_password);
    }

    @Override
    public void registerSuccess() {
        ToastUtils.showShort("注册成功");
        finish();
    }

    @Override
    public boolean isBaseOnWidth() {
        if (ScreenUtil.isScreenSizeLarge(this)) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public float getSizeInDp() {
        if (ScreenUtil.isScreenSizeLarge(this)) {
            return 667;
        } else {
            return 360;
        }
    }
}
